﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace LowLevelGraphics.Extractors
{
    /// <summary>
    /// 
    /// </summary>
    public class DefaultSizeSampler : IImagePyramidSampler
    {
        private UnsafeBitmap m_Bitmap = null;
        private float m_fResizeFactorWidth = 1.0f;
        private float m_fResizeFactorHeight = 1.0f;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="_bitmap"></param>
        /// <param name="_fResizeFactorWidth"></param>
        /// <param name="_fResizeFactorHeight"></param>
        public DefaultSizeSampler(UnsafeBitmap _bitmap, float _fResizeFactorWidth, float _fResizeFactorHeight)
        {
            m_Bitmap = _bitmap;
            m_fResizeFactorWidth = _fResizeFactorWidth;
            m_fResizeFactorHeight = _fResizeFactorHeight;
        }

        /// <summary>
        /// 
        /// </summary>
        public UnsafeBitmap Execute()
        {
            m_Bitmap = new UnsafeBitmap(
                (UnsafeBitmap)m_Bitmap.Clone(),
                new Size(
                    (int)(m_Bitmap.Width * m_fResizeFactorWidth),
                    (int)(m_Bitmap.Height * m_fResizeFactorHeight)
                )
            );
            return m_Bitmap;
        }

        /// <summary>
        /// 
        /// </summary>
        public UnsafeBitmap Bitmap
        {
            get { return m_Bitmap; }
        }
        /// <summary>
        /// 
        /// </summary>
        public SizeF ResizeFactor
        {
            get { return new SizeF(m_fResizeFactorWidth, m_fResizeFactorHeight); }
            set { m_fResizeFactorWidth = value.Width; m_fResizeFactorHeight = value.Height; }
        }
    }
}
